View Javadoc

1   // Heap2CodeReference.java, created Tue Feb 27  2:59:43 2001 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.Assembler;
5   
6   import java.io.DataOutput;
7   import java.io.IOException;
8   import joeq.Allocator.DefaultCodeAllocator;
9   import joeq.Memory.CodeAddress;
10  import joeq.Memory.HeapAddress;
11  
12  /***
13   * Heap2CodeReference
14   *
15   * @author  John Whaley <jwhaley@alum.mit.edu>
16   * @version $Id: Heap2CodeReference.java 1941 2004-09-30 03:37:06Z joewhaley $
17   */
18  public class Heap2CodeReference extends Reloc {
19  
20      HeapAddress from_heaploc;
21      CodeAddress to_codeloc;
22      
23      public Heap2CodeReference(HeapAddress from_heaploc, CodeAddress to_codeloc) {
24          this.from_heaploc = from_heaploc; this.to_codeloc = to_codeloc;
25      }
26  
27      public HeapAddress getFrom() { return from_heaploc; }
28      public CodeAddress getTo() { return to_codeloc; }
29      
30      public void patch() {
31          DefaultCodeAllocator.patchAbsolute(from_heaploc, to_codeloc);
32      }
33      
34      public void dumpCOFF(DataOutput out) throws IOException {
35          out.writeInt(from_heaploc.to32BitValue()); // r_vaddr
36          out.writeInt(0);                           // r_symndx
37          out.writeChar(Reloc.RELOC_ADDR32);         // r_type
38      }
39      
40      public String toString() {
41          return "from heap:"+from_heaploc.stringRep()+" to code:"+to_codeloc.stringRep();
42      }
43  
44      public boolean equals(Heap2CodeReference that) {
45          if (this.from_heaploc.difference(that.from_heaploc) != 0)
46              return false;
47          return true;
48      }
49      
50      public boolean equals(Object obj) {
51          if (obj instanceof Heap2CodeReference) {
52              return equals((Heap2CodeReference) obj);
53          }
54          return false;
55      }
56      
57      public int hashCode() {
58          // Note: hash code changes depending on address relocation!
59          int v1 = from_heaploc.to32BitValue();
60          return v1;
61      }
62  }